package com.sdust.user;

import com.sdust.common.properties.WeChatProperties;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;

@SpringBootApplication
@EnableConfigurationProperties(WeChatProperties.class)  //此注解和@ComponentScan注解作用一样，@ComponentScan注解已扫描到JwtProperties类
@MapperScan("com.sdust.user.mapper")
@ComponentScan(basePackages = {
        "com.sdust.user",        // 当前模块
        "com.sdust.common"        // 其他模块中包含 Bean 的包
})
public class SdustTalkUserApplication {

    public static void main(String[] args) {
        SpringApplication.run(SdustTalkUserApplication.class, args);
    }

    /**
     * 添加RestTemplate实例
     * @return
     */
    @Bean("restTemplate")
    public RestTemplate restTemplate(){
        RestTemplate restTemplate = new RestTemplate();
        MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
        mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Arrays.asList(
                MediaType.TEXT_HTML,
                MediaType.TEXT_PLAIN));
        restTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);

        return restTemplate;
    }

    /**
     * 消息队列-消息转换器
     * @return
     */
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }

}
